package com.clock.common.task;

import com.clock.common.constant.ChickenSoupKey;
import com.clock.service.ChickenSoupService;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class ChickenSoupTask {

    /*定时任务规则---对着抄     https://blog.csdn.net/qianlixiaomage/article/details/106599951  */

    @Resource
    StringRedisTemplate stringRedisTemplate;
    
    @Resource
    ChickenSoupService chickenSoupService;

    //每天12点清除鸡汤当天的缓存，顺便查下一条
    @Scheduled(cron = "0 0 0 * * ?")
    public void clearCache(){
        stringRedisTemplate.delete(ChickenSoupKey.CHICKEN_SOUP_KEY);
        String chickenSoup = chickenSoupService.getChickenSoup();
    }

}
